package com.zks.springbootcrud.controller;

import com.zks.springbootcrud.VO.DepartVO;
import com.zks.springbootcrud.VO.Staff_DepartVO;
import com.zks.springbootcrud.entity.Depart;
import com.zks.springbootcrud.entity.Staff;
import com.zks.springbootcrud.mapper.DepartMapper;
import com.zks.springbootcrud.mapper.StaffMapper;
import com.zks.springbootcrud.service.StaffServiceImp;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/springbootcrud")
public class StaffController {

    @Resource
    StaffServiceImp staffServiceImp;

    @Resource
    StaffMapper staffMapper;

    @Resource
    DepartMapper departMapper;

    @RequestMapping("/findStaff/{id}")
    public Staff findStaff(@PathVariable("id") int id){

        Staff staff=staffServiceImp.findStaffById(id);
        return staff;
    }

    @RequestMapping("/addStaff")
    public int addStaff(){

        Staff staff=new Staff();
        staff.setName("zhang");
        staff.setAge("10");
        staff.setTel("123456");
        staff.setState("在职");
        int sa=staffServiceImp.insertStaff(staff);
        //返回受影响行数
        return sa;

    }

    @RequestMapping("/deleteStaff/{id}")
    public void deleteStaffById(@PathVariable("id") int id){

        staffServiceImp.deleteStaffById(id);
    }

    //测试，获取员工所属的部门信息
    @RequestMapping("/getDepartStaff")
    public Staff_DepartVO GetDepartmentStaff(){

        return staffMapper.selectStaffAndHisDepart(1);

    }

    //获取部门所属的所有员工信息
    @RequestMapping("/GetDepartmentStaffList/{id}")
    public DepartVO GetDepartmentStaffList(@PathVariable("id") int id){

        return departMapper.getDepartStaffList(id);
    }

/*    @RequestMapping("/GetDepartmentStaffList")
    public List<Staff> GetDepartmentStaffList(){

        return staffMapper.returnDepartStaffList(1);
    }*/

}
